package com.tf_cut.backend.agent.service;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.tf_cut.backend.agent.vo.AgentAccountDetailVo;
import com.tf_cut.backend.agent.vo.AgentAndAccountVo;
import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.mapper.AgentAndAccountMapper;

@Service
public class AgentAndAccountServiceImpl implements AgentAndAccountService {
	
	@Autowired
	private AgentAndAccountMapper agentAndAccountMapper;

	@Override
	public PageInfo<AgentAndAccountVo> findListAgent(AgentAndAccountVo avo) {
		PageHelper.startPage(avo.getPage() , avo.getRows());
		List<AgentAndAccountVo> listVo = agentAndAccountMapper.findListAgent(avo);
		com.github.pagehelper.PageInfo<AgentAndAccountVo> pageinfo = new com.github.pagehelper.PageInfo<>(listVo);
		
		PageInfo<AgentAndAccountVo> returnPageInfo = new PageInfo<>();
		returnPageInfo.setPage(pageinfo.getPageNum());//页码
		returnPageInfo.setPageSize(pageinfo.getPageSize());//页面大小
		returnPageInfo.setRows(pageinfo.getList());//分页结果
		returnPageInfo.setRecords((int)pageinfo.getTotal());//总记录数
		returnPageInfo.setTotal(pageinfo.getPages());//总页数
		return returnPageInfo;
	}
	
	@Override
	public List<AgentAndAccountVo> findListAgentNoPage(AgentAndAccountVo avo) {
		return agentAndAccountMapper.findListAgent(avo);
	}

	@Override
	public List<AgentAndAccountVo> findAgentAccountwithagentIds(List<String> agentIds) {
		return agentAndAccountMapper.findAgentAccountwithagentIds(agentIds);
	}

	@Override
	public PageInfo<AgentAccountDetailVo> findAgentAccountDetail(AgentAccountDetailVo avo) {
		PageHelper.startPage(avo.getPage() , avo.getRows());
		List<AgentAccountDetailVo> listVo = agentAndAccountMapper.findDetailAccount(avo);
		com.github.pagehelper.PageInfo<AgentAccountDetailVo> pageinfo = new com.github.pagehelper.PageInfo<>(listVo);
		
		PageInfo<AgentAccountDetailVo> returnPageInfo = new PageInfo<>();
		returnPageInfo.setPage(pageinfo.getPageNum());//页码
		returnPageInfo.setPageSize(pageinfo.getPageSize());//页面大小
		returnPageInfo.setRows(pageinfo.getList());//分页结果
		returnPageInfo.setRecords((int)pageinfo.getTotal());//总记录数
		returnPageInfo.setTotal(pageinfo.getPages());//总页数
		return returnPageInfo;
		
	}

	@Override
	public List<AgentAccountDetailVo> findAgentAccountDetailNoPage(AgentAccountDetailVo avo) {
		List<AgentAccountDetailVo> listVo = agentAndAccountMapper.findDetailAccount(avo);
		return listVo;
	}

	@Override
	public List<AgentAndAccountVo> qryUnBindAgent(String agentId) {
		return agentAndAccountMapper.qryUnBindAgent(agentId);
	}

	@Override
	public int bindAgent(String agentId, List<String> agentIds) {
		return agentAndAccountMapper.bindAgent(agentId,agentIds);
	}

	@Override
	public int unBindAgent(String agentId) {
		return agentAndAccountMapper.unBindAgent(agentId);
	}
}
